package com.bdmc.web.controller.report;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.vo.ReportCheckPointVo;
import com.bdmc.report.domain.bo.ReportCheckPointBo;
import com.bdmc.report.service.IReportCheckPointService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 人员,车辆检查点工作及里程统计控制器
 *
 * @author bdmc
 * @date 2022-03-11
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/checkPoint")
public class ReportCheckPointController extends BaseController {

    private final IReportCheckPointService iReportCheckPointService;

    /**
     * 查询人员,车辆检查点工作及里程统计列表
     */
    @SaCheckPermission("report:checkPoint:list")
    @GetMapping("/list")
    public TableDataInfo<ReportCheckPointVo> list(@Validated(QueryGroup.class) ReportCheckPointBo bo, PageQuery pageQuery) {
        return iReportCheckPointService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出人员,车辆检查点工作及里程统计列表
     */
    @SaCheckPermission("report:checkPoint:export")
    @Log(title = "检查点工作及里程统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportCheckPointBo bo, HttpServletResponse response) {
        List<ReportCheckPointVo> list = iReportCheckPointService.queryList(bo);
        ExcelUtil.exportExcel(list, "检查点工作及里程统计", ReportCheckPointVo.class, response);
    }

    /**
     * 获取人员,车辆检查点工作及里程统计详细信息
     */
    @SaCheckPermission("report:checkPoint:query")
    @GetMapping("/{reportPointId}")
    public AjaxResult<ReportCheckPointVo> getInfo(@PathVariable("reportPointId") Long reportPointId) {
        return AjaxResult.success(iReportCheckPointService.queryById(reportPointId));
    }

    /**
     * 新增人员,车辆检查点工作及里程统计
     */
    @SaCheckPermission("report:checkPoint:add")
    @Log(title = "检查点工作及里程统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportCheckPointBo bo) {
        return toAjax(iReportCheckPointService.insertByBo(bo));
    }

    /**
     * 修改人员,车辆检查点工作及里程统计
     */
    @SaCheckPermission("report:checkPoint:edit")
    @Log(title = "检查点工作及里程统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportCheckPointBo bo) {
        return toAjax(iReportCheckPointService.updateByBo(bo));
    }

    /**
     * 删除人员,车辆检查点工作及里程统计
     */
    @SaCheckPermission("report:checkPoint:remove")
    @Log(title = "检查点工作及里程统计" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportPointIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] reportPointIds) {
        return toAjax(iReportCheckPointService.deleteWithValidByIds(Arrays.asList(reportPointIds), true));
    }
}
